package javatest;

/**
 * Created by lenovo on 2016/4/8.
 */
import java.util.Scanner;

public class CaesarCipher {
    private String table;
    private int key;

    public CaesarCipher(String table, int key) {
        super();
        this.table = table;
        this.key = key;
    }

    public String encrypt(String from) {
        String to = "";
        for (int i = 0; i < from.length(); i++) {
            to += table.charAt((table.indexOf(from.charAt(i))+key)%table.length());

        }
        return to;
    }

    public static void main(String[] args) {
        CaesarCipher caesarCipher=new
                CaesarCipher("abcdefghijklmnopqrstuvwxyz",3);
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要加密的字符串");
        String str=scanner.nextLine();

                String result=caesarCipher.encrypt(str);
        System.out.print(result);
    }

}
